﻿


@model WebApp.Models.Category

@{
    ViewBag.Title = "Edit";
}




<div class="container-fluid">
    <!-- Page Heading -->
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">
                Category
                <small>Edit</small>
            </h1>
            <ol class="breadcrumb">
                <li>
                    <i class="fa fa-home"></i>  @Html.ActionLink("Home", "Index", "Home")
                </li>
                 <li>
                    <i class="fa fa-folder-open"></i>  @Html.ActionLink("Categories", "Index", "Categories")
                </li>
                <li class="active">
                    <i class="fa fa-file"></i> Edit
                </li>
            </ol>
        </div>
    </div>
    <!-- /.row -->
     <div class="row">
        <div class="col-lg-12">

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
        <div class="form-horizontal">
        <h4>Category</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.Partial("EditForm")
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" class="btn btn-primary" value="Save" />
                <input type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal" value="Delete" />
            </div>
        </div>
    </div>
}
</div>
</div>
 </div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Warning !!</h4>
            </div>
            <div class="modal-body">
                Are you sure you want to delete this item ?
            </div>
            <div class="modal-footer">
                @using (Html.BeginForm("Delete", "Categories", new { id=Model.Id}))
                {
                    @Html.AntiForgeryToken()
                    <button type="button" class="btn btn-default" data-dismiss="modal"> 取消 </button>
                    <button type="submit" class="btn btn-warning"> 保存 </button>
                }
            </div>
        </div>
    </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript">
	
    		var categoryid = 0;
		var ObjectState = "Modified";   
                                 
             var $productstable = {};
                        $(document).ready(function () {
				categoryid = $('#Id', 'form').val();
                $('form').submit(function () {
					if (!$('form').valid())
						return false;
                    var token = $('[name=__RequestVerificationToken]').val();
                    var serializedForm = $(this).serialize();
                    var actionurl = $(this).attr('action');
                                         
                        var products = $productstable.bootstrapTable('getData');
                                         
                     var newitem = {
						

                        								//primaryKey   
								Id: categoryid,
                                                        Name: $('#Name', 'form').val(),
                        								//detailTables
                                Products: products ,
                                                ObjectState:ObjectState 
                    };
                    $.ajax({
                        url: actionurl,
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify(newitem),
                        success: function (result) {
                            if (result.success) {
                                self.location = "/Categories/Index";
                            } else {
                                alert(result.err);
                            }
                            
                        },
                        error: function (result) {
                            console.log(result.statusText + result.responseText);
                            alert(result.statusText + result.responseText);
                        }
                    });
                    return false;
                    

                });
            });
      
      </script>

}
